/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.um.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jinhe.tss.core.Global;
import com.jinhe.tss.core.sso.SSOConstants;
import com.jinhe.tss.core.web.dispaly.XmlPrintWriter;
import com.jinhe.tss.core.web.dispaly.xmlhttp.XmlHttpEncoder;
import com.jinhe.tss.um.service.ILoginService;

/**
 * <p>
 * 通过用户登录名，获取用户认证方式及用户名<br>
 * </p>
 */
public class GetLoginInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 8680769606094382553L;
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ILoginService service = (ILoginService) Global.getContext().getBean("LoginService");
        
        String loginName = request.getParameter(SSOConstants.LOGINNAME_IN_SESSION);
        String[] info = service.getLoginInfoByLoginName(loginName);

        response.setContentType("text/html;charset=GBK");
        
        XmlHttpEncoder encoder = new XmlHttpEncoder();
        encoder.put("UserName", info[0]); //返回用户姓名
        encoder.put("ClassName", info[1]); //返回身份认证器类名：全路径
        encoder.print(new XmlPrintWriter(response.getWriter()));
    }

}
